//
//  CommentHeaderView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/18.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class CommentHeaderView: UITableViewHeaderFooterView {
    var headBlock:(() -> Void)?
    
    let headImage = UIImageView()
    let nameLabel = UILabel()
    let contentLabel = UILabel()
    let timeLabel = UILabel()
    let numberImage = UIImageView()
    let numberLabel = UILabel()
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        
        // Content View
        contentView.backgroundColor = UIColor.white

        contentView.addSubview(self.headImage)
        contentView.addSubview(self.nameLabel)
        contentView.addSubview(self.timeLabel)
        contentView.addSubview(self.contentLabel)
        contentView.addSubview(self.numberImage)
        contentView.addSubview(self.numberLabel)
        
        self.headImage.frame = CGRect(x:13.5, y:10, width:30, height:30)
        self.headImage.layer.cornerRadius = 15
        self.headImage.layer.masksToBounds = true
 
        self.nameLabel.frame = CGRect(x:55, y:10, width:SCREEN_WIDTH / 2, height:18.5)
        self.nameLabel.font = Font_Medium(13)
        self.nameLabel.textColor = RGB_Same(136)
        
        weak var weakNameLabel = nameLabel
        self.contentLabel.snp.updateConstraints { (make) in
            make.left.equalToSuperview().offset(55)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo((weakNameLabel?.snp.bottom)!).offset(5)
            make.bottom.equalToSuperview().offset(-33.5)
        }
        self.contentLabel.numberOfLines = 0
        self.contentLabel.font = Font_Medium(13)
        self.contentLabel.textColor = RGB_Same(53)
        
        weak var weakContentLabel = contentLabel
        self.timeLabel.snp.updateConstraints { (make) in
            make.left.equalToSuperview().offset(55)
            make.right.equalToSuperview().offset(-100)
            make.top.equalTo((weakContentLabel?.snp.bottom)!).offset(8.5)
            make.bottom.equalToSuperview().offset(-10)
        }
        self.timeLabel.font = Font_Medium(11)
        self.timeLabel.textColor = RGB_Same(136)
        
        self.numberImage.snp.updateConstraints { (make) in
            make.right.equalToSuperview().offset(-40)
            make.top.equalTo((weakContentLabel?.snp.bottom)!).offset(8.5)
            make.width.equalTo(15)
            make.height.equalTo(15)
        }
        self.numberImage.image = IMAGE(name: "icon_评论")
        
        weak var weakNumberImage = numberImage
        self.numberLabel.snp.updateConstraints { (make) in
            make.left.equalTo((weakNumberImage?.snp.right)!).offset(4)
            make.right.equalToSuperview().offset(-5)
            make.top.equalTo((weakContentLabel?.snp.bottom)!).offset(8.5)
            make.height.equalTo(15)
        }
        self.numberLabel.font = Font_Medium(11)
        self.numberLabel.textColor = RGB_Same(136)
        
        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(CommentHeaderView.tapHeader(_:))))
        
        
    }
    
    @objc func tapHeader(_ gestureRecognizer: UITapGestureRecognizer) {
        headBlock?()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
